package com.itsm.example.incident.controller;

import com.itsm.example.audit.pojo.context.AuditContext;
import com.itsm.example.audit.pojo.dto.Result;
import com.itsm.example.incident.flow.bo.IncidentContext;
import com.itsm.example.incident.service.IncidentService;
import com.itsm.example.statemachine.bo.ItsmEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@RequestMapping("/incident")
@Slf4j
public class IncidentController {

    @Autowired
    private IncidentService incidentService;
    @PostMapping("/addAndProcess")
    public Result addAndProcess(@RequestBody IncidentContext incidentContext) {
        log.info(incidentContext.toString());
        return Result.success( incidentService.addAndProcess(incidentContext));
    }

    @PostMapping("/process")
    public Result process(@RequestBody IncidentContext incidentContext) {
        log.info(incidentContext.toString());
        return Result.success( incidentService.process(incidentContext));
    }


    @GetMapping("/getNextStep")
    public Result getNextStep(long id){
        List<ItsmEvent> eventList = incidentService.getNextStep(IncidentContext.builder().id(id).build());
        log.info("getNextStep:{}", eventList);
        return Result.success(eventList.toString());
    }
}
